<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="108px">
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          size="small"
        />
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select v-model="queryParams.classId" clearable filterable placeholder="请选择班级">
          <el-option
            v-for="item in classList"
            :key="item.id"
            :label="item.label"
            :value="parseInt(item.id)"
            size="small">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="药品名称" prop="medicantName">
          <el-input
            v-model="queryParams.medicantName"
            placeholder="请输入药品名称"
            size="small"
          />
        </el-form-item>
        <el-form-item label="用药用量" prop="usageMeasure">
          <el-input
            v-model="queryParams.usageMeasure"
            placeholder="请输入用药用量"
            type="input"
            size="small"
          />
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="studentList">
      <el-table-column label="姓名" align="center" prop="studentName"/>
      <el-table-column label="班级" align="center" prop="className"/>
      <el-table-column label="药品名称" align="center" prop="medicantName"/>
      <el-table-column label="喂药时间" align="center" prop="time"/>
      <el-table-column label="用药用量" align="center" prop="usageMeasure"/>
      <el-table-column label="喂药状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.medicine_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="药品图片" align="center" prop="medicantImage">
        <template slot-scope="scope">
          <el-image
            style="width: 120px;height: 60px;"
            :src="scope.row.medicantImage"
            lazy
            :preview-src-list="[scope.row.medicantImage]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="approveHandle(scope.row)"
          >审批
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>


import { selectName} from '@/api/base/device'
import {selectClazz} from "@/api/base/clazz";
import {addmedicantApply, updatemedicantApply,noFeedList,feedDetail} from "@/api/base/ill";

export default {
  name: "feedapply",
  dicts:['medicant_apply','medicine_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolCode:this.$store.getters.schoolCode,
        studentName: '',
        classId: null,
        medicantName: '',
        usageDosage: '',
        usageMeasure: '',
        applyStatus: null
      },
      classList: [],
      total: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      form: {},
    };
  },
  created() {
    //班级
    this.getQueryClazzList();
    this.getList()
  },
  methods: {
    approveHandle(row){
      const queryParams = this.queryParams;
       this.$confirm('是否确认已喂药?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.feedDetail(row)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消确认'
          });
        });
    },
    async feedDetail(row){
      row.status = '1'
      const res = await feedDetail(row)
      if(res.code == 200){
        this.getList()
      }else {
        this.msgError(res.msg);
      }
    },
    /** 查询班级列表 */
    async getQueryClazzList() {
      try{
        this.loading = true;
        const {rows}=await selectClazz();
        this.classList=rows.map(item=>{
          return {
            id:item.id,
            label:item.title,
          }
        })
        this.loading = false;
      }catch (e) {
        console.log(e)
      }
    },
    async getList() {
      try {
        this.loading = true;
        const data=await noFeedList(this.queryParams);
        this.studentList = data.rows;
        this.total = data.total;
        this.loading = false;
      } catch (e) {
        console.log(e)
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        schoolCode: null,
        status: null,
        studentName:'',
        classId:null,
        medicantName:'',
        usageMeasure:'',

      };
      this.resetForm("form");
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog .el-form-item__content {
  width: 67%;
}
::v-deep .el-select{
  width: 100%;
}
</style>
